home *** CD-ROM | disk | FTP | other *** search
/ JCSM Shareware Collection 1996 September / JCSM Shareware Collection (JCS Distribution) (September 1996).ISO / prgtools / euphor13.zip / INSTALL.EX < prev    next >
Text File  |  1995-04-25  |  13KB  |  455 lines

  1.         -----------------------------------
  2.         --  Program to Install Euphoria  --
  3.         --  (see install.doc)            --
  4.         -----------------------------------
  5.  
  6. include file.e
  7. include graphics.e
  8. include wildcard.e
  9.  
  10. constant KEYBOARD = 0, SCREEN = 1
  11. constant SUCCESS = 1, FAILURE = 0, NO_EDIT = 2
  12. constant TRUE = 1, FALSE = 0
  13. constant CLEAR = 0, NO_CLEAR = 2
  14.  
  15.     -------------------------------------------------
  16.     -- Subdirectory structure for Euphoria files.  --
  17.     -------------------------------------------------
  18.  
  19. constant file_list = {
  20.   {"BIN", 
  21.    "BIN.DOC", "SYNCOLOR.E", "LINES.BAT", "LINES.EX", "EPRINT.EX",   
  22.    "EPRINT.BAT", "SHROUD.EX", "ED.BAT", "ED.EX", "KEYWORDS.E", "SB.BAT", 
  23.    "SWAPON.BAT", "SWAPOFF.BAT", "SEARCH.EX", "SEARCH.BAT", "FREQ.EX", 
  24.    "DOS4GW.EXE", "EX.EXE"},
  25.   
  26.   {"DOC", 
  27.    "WHAT2DO.DOC", "ED.DOC", "REFMAN.DOC", "LIBRARY.DOC", "C.DOC", "BASIC.DOC", 
  28.    "REGISTER.DOC", "RELNOTES.DOC", "ORDER.FRM", "INSTALL.DOC", "EPIC.DOC"},
  29.  
  30.   {"DEMO",
  31.    "BITMAP.EX", "DEMO.DOC", "PLOT3D.EX", "ANIMAL.EX", "ALLSORTS.EX",  
  32.    "EXAMPLE.EX", "SB.EX", "SELECT.E", "TTT.EX", "SIMPLE.EX", "LEARN.EX",
  33.    "WIRE.EX", "SANITY.EX", "MOUSE.EX", "MSET.EX", "QUEENS.EX", "BUZZ.EX",
  34.    "POLYGON.EX", "CALLMACH.EX", "MYDATA.EX", "STEREO.EX", "PICTURE"},
  35.  
  36.   {"DEMO\\LANGWAR", 
  37.    "LW.DOC", "LW.SUM", "WEAPONS.E", "SCREEN.E", "COMMANDS.E", "DAMAGE.E",  
  38.    "DISPLAY.E", "EMOVE.E", "ENEMY.E", "SCHED.E", "VARS.E", "SOUNDEFF.E",  
  39.    "LW.EX"},   
  40.  
  41.   {"DEMO\\BENCH", 
  42.    "BENCH.DOC", "SHELL.EX", "SHELL.BAS", "DATABASE.EX", "DATABASE.BAS", 
  43.    "SIEVE.EX", "SIEVE.BAS", "SEQUENCE.EX", "SEQUENCE.BAS", "FILESORT.EX"},   
  44.   
  45.   {"INCLUDE", 
  46.    "GRAPHICS.E", "SORT.E", "GET.E", "MOUSE.E", "FILE.E", "MACHINE.E",
  47.    "WILDCARD.E", "IMAGE.E"}  
  48. }
  49.  
  50.  
  51. constant move_command = "c:\\dos\\move.exe "
  52.  
  53. integer try_move
  54. try_move = sequence(dir(move_command)) -- DOS 6
  55.  
  56. sequence vc
  57. vc = video_config()
  58.  
  59. integer color_monitor
  60. color_monitor = vc[VC_COLOR]
  61.  
  62. procedure the_end()
  63. -- exit install
  64.     puts(SCREEN, "\nPress Enter...\n")
  65.     if atom(gets(0)) then
  66.     end if
  67.     abort(1)
  68. end procedure
  69.  
  70. procedure fore_color(integer c)
  71. -- change foreground color
  72.     if color_monitor then
  73.     text_color(c)
  74.     end if
  75. end procedure
  76.  
  77. procedure move(sequence source, sequence dest)
  78. -- move one file into a directory
  79.  
  80.     puts(SCREEN, "    " & source & '\n')
  81.  
  82.     -- MOVE (DOS 6)
  83.     if try_move then
  84.     system(move_command & source & ' ' & dest & " > NUL", NO_CLEAR)
  85.     if sequence(dir(dest & "\\" & source)) then
  86.         return
  87.     else
  88.         puts(SCREEN, "OK - no MOVE command - use COPY instead ...\n")
  89.         try_move = FALSE
  90.     end if
  91.     end if
  92.  
  93.     -- COPY (DOS 5 or earlier)
  94.     system("copy " & source & ' ' & dest & " > NUL", NO_CLEAR)
  95.     if sequence(dir(dest & "\\" & source)) then
  96.     system("del " & source, NO_CLEAR)
  97.     else
  98.     -- copy failed
  99.     puts(SCREEN, "Unable to copy " & source & 
  100.              " to " & dest & " subdirectory\n")
  101.     if sequence(dir(source)) and 
  102.        ( sequence(dir("euphor12.zip")) or 
  103.          sequence(dir("euph12.zip")) ) then
  104.         puts(SCREEN, "Perhaps you can try again without the .zip file\n")
  105.     end if
  106.     end if
  107. end procedure
  108.  
  109. procedure moveall()
  110. -- move all files into the correct subdirectories
  111.     sequence command
  112.     integer f
  113.  
  114.     f = open("bin\\dos4gw.exe", "rb")
  115.     if f != -1 then
  116.     close(f)
  117.     puts(SCREEN, "Subdirectory structure has been set up\n")
  118.     return
  119.     end if
  120.     puts(SCREEN, "Creating Euphoria Subdirectories ...\n\n")
  121.     for i = 1 to length(file_list) do
  122.     command = "mkdir " & file_list[i][1]
  123.     puts(SCREEN, command & '\n')
  124.     system(command, NO_CLEAR) 
  125.     for j = 2 to length(file_list[i]) do
  126.         move(file_list[i][j], file_list[i][1])
  127.     end for
  128.     end for
  129.     system("del unzip.doc", NO_CLEAR) -- not needed anymore
  130. end procedure
  131.  
  132. function setupdir()
  133. -- set up subdirectories 
  134.     moveall()
  135.     if atom(dir("BIN\\EX.EXE")) then
  136.     puts(SCREEN, "Subdirectory set up failed - see install.doc\n")
  137.     return FAILURE
  138.     end if
  139.     return SUCCESS
  140. end function
  141.  
  142. procedure rename_it()
  143.     puts(SCREEN, 
  144.      "Please remove it or rename it before installing a new version.\n")
  145. end procedure
  146.  
  147. function copy_to_hard_disk(integer drive)
  148. -- copy Euphoria files to EUPHORIA directory 
  149.     sequence eu_dir, rename_dir
  150.     integer rename_letter
  151.  
  152.     eu_dir = drive & ":\\EUPHORIA"
  153.  
  154.     if compare(upper(current_dir()), eu_dir) = 0 then
  155.     -- we're in EUPHORIA directory already - just set up subdirectories
  156.     return setupdir() 
  157.     end if
  158.     
  159.     if sequence(dir(eu_dir)) then
  160.     puts(SCREEN,
  161.     "An existing EUPHORIA directory was found on drive " & drive & ".\n")
  162.     if try_move then
  163.         rename_letter = 'F'
  164.         while rename_letter <= 'Z' do
  165.         rename_dir = drive & ":\\" & rename_letter & "UPHORIA"
  166.         if atom(dir(rename_dir)) then
  167.             exit
  168.         end if
  169.         rename_letter = rename_letter + 1
  170.         end while
  171.         if rename_letter <= 'Z' then
  172.         system(move_command & eu_dir & ' ' & rename_dir & "> NUL", NO_CLEAR)
  173.         if sequence(dir(rename_dir)) then
  174.             puts(SCREEN,"It has been renamed as " & rename_dir & "\n\n")
  175.         else
  176.             rename_it()
  177.             return FAILURE
  178.         end if
  179.         else
  180.         rename_it()
  181.         return FAILURE
  182.         end if
  183.     else
  184.         rename_it()
  185.         return FAILURE
  186.     end if
  187.     end if
  188.     
  189.     puts(SCREEN, "The EUPHORIA files will now be copied to " & eu_dir & '\n')
  190.     puts(SCREEN, "    * Press Enter to start copying. [recommended action]\n")
  191.     puts(SCREEN, "    * or type ! to abort.\n")
  192.     
  193.     if find('!', gets(KEYBOARD)) then
  194.     puts(SCREEN, "\ninstallation aborted - try again later\n")
  195.     the_end()
  196.     end if
  197.     
  198.     system("mkdir " & eu_dir, NO_CLEAR)
  199.     if atom(dir(eu_dir)) then
  200.     puts(SCREEN, "\n\nCouldn't create " & eu_dir & ".\n")
  201.     puts(SCREEN, "See install.doc\n")
  202.     return FAILURE
  203.     end if
  204.     
  205.     -- copy all files to EUPHORIA directory
  206.     system("xcopy *.* " & eu_dir, CLEAR)
  207.     if atom(dir(eu_dir & "\\EX.EXE")) then
  208.     puts(SCREEN, "copy failed - see install.doc\n")
  209.     return FAILURE
  210.     end if
  211.     
  212.     -- copy worked, now cd to EUPHORIA
  213.     system(drive & ':', NO_CLEAR)
  214.     system("cd " & eu_dir, NO_CLEAR)
  215.     if compare(upper(current_dir()), eu_dir) != 0 then
  216.     puts(SCREEN, "cd failed - see install.doc\n")
  217.     return FAILURE
  218.     end if
  219.     
  220.     -- cd worked, now set up subdirectories
  221.     return setupdir() 
  222.  
  223. end function
  224.  
  225. constant MAX_PATH = 127 - length("C:\\EUPHORIA\\BIN; ")
  226.  
  227. function edit_auto_exec(integer drive)
  228. -- edit the autoexec.bat file
  229. -- add to the PATH, set EUDIR
  230.     integer path_found, q, auto_exec_no, p, white, semi_pos
  231.     sequence path, auto_exec, auto_name, base_name, answer, set_line
  232.     object line
  233.  
  234.     path = getenv("PATH")
  235.     if sequence(path) then
  236.     if match("EUPHORIA\\BIN", path) then
  237.         puts(SCREEN, "\nYour current PATH already has EUPHORIA\\BIN\n")
  238.         return NO_EDIT
  239.     end if
  240.     if length(path) >= MAX_PATH then
  241.         puts(SCREEN, "\nYour current PATH is too long to add EUPHORIA\\BIN\n")
  242.         puts(SCREEN, "Perhaps you can remove a directory from it.\n")
  243.         return FAILURE
  244.     end if
  245.     end if
  246.     puts(SCREEN, "\n\nEditing autoexec.bat ...\n")
  247.     base_name = ":\\autoexec.bat"
  248.     auto_name = "C" & base_name  -- try C first
  249.     auto_exec_no = open(auto_name, "r")
  250.     while auto_exec_no = -1 do
  251.     puts(SCREEN, "Couldn't open " & auto_name & '\n')
  252.     puts(SCREEN, "On what drive is your autoexec.bat file?\n")
  253.     puts(SCREEN, "Type a letter: (! to abort)\n")
  254.     answer = gets(KEYBOARD)
  255.     if find('!', answer) then
  256.         puts(SCREEN, "\ninstallation aborted - see install.doc Part B\n")
  257.         the_end()
  258.     end if
  259.     auto_name = answer[1] & base_name
  260.     auto_exec_no = open(auto_name, "r")
  261.     end while
  262.     -- read in the entire autoexec.bat
  263.     auto_exec = {}
  264.     path_found = 0
  265.     while TRUE do
  266.     line = gets(auto_exec_no)
  267.     if atom(line) then
  268.         exit
  269.     end if
  270.     p = match("PATH", upper(line))
  271.     if p then
  272.         -- line contains the word "PATH" in upper or lower case
  273.         -- at position p
  274.         white = TRUE
  275.         q = p - 1
  276.         while q >= 1 do
  277.         if not find(line[q], " \t") then
  278.             -- non whitespace - only "SET" is allowed
  279.             if q >= 3 then
  280.             if compare("SET", upper(line[q-2..q])) = 0 then
  281.                 q = q - 2
  282.             else
  283.                 white = FALSE
  284.                 exit
  285.             end if
  286.             else
  287.             white = FALSE
  288.             exit
  289.             end if
  290.         end if
  291.         q = q - 1
  292.         end while
  293.        
  294.         if white and find(line[p+4], " \t=") then
  295.         -- this is a PATH line
  296.         path_found = path_found + 1
  297.         if path_found = 1 then
  298.             -- only change the first one encountered
  299.             set_line = "SET EUDIR=" & drive & ":\\EUPHORIA\n"
  300.             auto_exec = append(auto_exec, set_line)
  301.             if match(drive & ":\\EUPHORIA\\BIN", upper(line)) then
  302.             -- its already there
  303.             puts(SCREEN, "PATH already has " & drive & 
  304.                      ":\\EUPHORIA\\BIN\n")
  305.             close(auto_exec_no)
  306.             return NO_EDIT
  307.             end if
  308.             if length(line) > MAX_PATH then
  309.             -- line is too long (MS-DOS restriction)
  310.             puts(SCREEN, 
  311.             "Your PATH line is too long to add EUPHORIA\\BIN\n")
  312.             puts(SCREEN, 
  313.             "Perhaps you can delete a directory from it.\n")
  314.             puts(SCREEN, 
  315.             "No changes were made to your autoexec.bat file.\n")
  316.             close(auto_exec_no)
  317.             return FAILURE
  318.             end if
  319.             semi_pos = find(';', line)
  320.             if semi_pos = 0 then
  321.             semi_pos = length(line)
  322.             line = line[1..length(line)-1] & ";\n"
  323.             end if
  324.             -- add EUPHORIA\BIN to path
  325.             puts(SCREEN, "Changing this line:\n")
  326.             fore_color(2)
  327.             puts(SCREEN, line)
  328.             fore_color(7)
  329.             puts(SCREEN, "to:\n")
  330.             fore_color(2)
  331.             puts(SCREEN, line[1..semi_pos])
  332.             fore_color(4)
  333.             puts(SCREEN, drive & ":\\EUPHORIA\\BIN;")
  334.             fore_color(2)
  335.             puts(SCREEN, line[semi_pos+1..length(line)])
  336.             line = line[1..semi_pos] &
  337.                drive & ":\\EUPHORIA\\BIN;" &
  338.                line[semi_pos+1..length(line)]
  339.             fore_color(7)
  340.             puts(SCREEN, "and inserting the following line:\n")
  341.             fore_color(4)
  342.             puts(SCREEN, set_line)
  343.             fore_color(7)
  344.         end if
  345.         end if
  346.     end if
  347.     auto_exec = append(auto_exec, line)
  348.     end while
  349.     close(auto_exec_no)
  350.  
  351.     if not path_found then
  352.     puts(SCREEN, "The PATH command could not be found.\n")
  353.     puts(SCREEN, "No changes were made to your autoexec.bat.\n")
  354.     return FAILURE
  355.     else
  356.     -- write out the new autoexec.bat
  357.     puts(SCREEN, 
  358.     "Is it OK to make these changes to your autoexec.bat file? (y or n) \n")
  359.     puts(SCREEN, "-----> ") 
  360.     answer = upper(gets(KEYBOARD))
  361.     puts(SCREEN, '\n')
  362.     if not find('Y', answer) then
  363.         return FAILURE
  364.     end if
  365.     if path_found = 2 then
  366.         puts(SCREEN, "One other \"PATH\" line was found but not changed.\n") 
  367.         puts(SCREEN, "Please take a look at it.\n")
  368.     elsif path_found > 2 then
  369.         printf(SCREEN, "%d other \"PATH\" lines were found but not changed.\n",
  370.         path_found - 1)
  371.         puts(SCREEN, "Please take a look at them.\n")
  372.     end if
  373.     auto_exec_no = open(auto_name, "w")
  374.     if auto_exec_no = -1 then
  375.         puts(SCREEN, "Couldn't write out the new autoexec.bat!\n")
  376.         puts(SCREEN, "Your autoexec.bat file is read-only.\n")
  377.         return FAILURE
  378.     end if
  379.     for i = 1  to length(auto_exec) do
  380.         puts(auto_exec_no, auto_exec[i])
  381.     end for
  382.     close(auto_exec_no)
  383.     end if
  384.     return SUCCESS
  385. end function
  386.  
  387. procedure install()
  388. -- main routine for Euphoria installation
  389.     integer drive
  390.     integer edit_status
  391.     sequence answer
  392.     
  393.     clear_screen()
  394.     fore_color(5)
  395.     puts(SCREEN, "\nEuphoria")
  396.     fore_color(7)
  397.     puts(SCREEN, " Installation Program\n\n")
  398.     
  399.     if atom(dir("DOS4GW.EXE")) then
  400.     puts(SCREEN, 
  401.     "All files must be together in one directory to run install.\n")
  402.     return
  403.     end if
  404.  
  405.     puts(SCREEN, "On which drive do you want to put the EUPHORIA directory?\n")
  406.     puts(SCREEN, "Type the drive letter, or just hit Enter for drive C\n")
  407.     puts(SCREEN, "-----> ")
  408.     
  409.     answer = upper(gets(KEYBOARD))
  410.     
  411.     while answer[1] = ' ' or answer[1] = '\t' do
  412.     answer = answer[2..length(answer)]
  413.     end while
  414.  
  415.     drive = answer[1]
  416.     if drive < 'A' or drive > 'Z' then
  417.     drive = 'C'
  418.     end if
  419.  
  420.     puts(SCREEN, '\n')
  421.  
  422.     if copy_to_hard_disk(drive) = FAILURE then
  423.     return
  424.     end if
  425.  
  426.     edit_status = edit_auto_exec(drive)
  427.  
  428.     if edit_status = FAILURE then
  429.     puts(SCREEN, 
  430.     "To complete the install you should edit autoexec.bat manually.\n") 
  431.     puts(SCREEN, "See doc\\install.doc - Manual Procedure Part B\n")
  432.     return
  433.     end if
  434.  
  435.     puts(SCREEN, "\nInstall Completed.\n")
  436.     if edit_status = NO_EDIT then
  437.     puts(SCREEN, 
  438.     "You might start by looking at readme.doc or doc\\what2do.doc\n")
  439.     else
  440.     puts(SCREEN, "After pressing Enter, you should exit Windows, ")
  441.     puts(SCREEN, "remove any floppy disks,\nthen press Control-Alt-Delete")
  442.     puts(SCREEN, " to reboot your machine. ")
  443.     puts(SCREEN, "This will set\nyour PATH and EUDIR variables.\n\n")
  444.     puts(SCREEN, "When the system is back up you might start\n")  
  445.     puts(SCREEN, "by looking at readme.doc or doc\\what2do.doc.\n")
  446.     puts(SCREEN, 
  447.     "The Euphoria editor, ed, will be available - see doc\\ed.doc.\n")
  448.     end if
  449.     puts(SCREEN, "\n\t\tEnjoy!\n")
  450. end procedure
  451.  
  452. install()
  453. the_end()
  454.  
  455.